package com.franklin.ideaplugin.api.linemarker;

import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * @author Ye Junhui
 * @since 2023/5/12
 */
public abstract class AbstractLineMarkerProvider<T extends PsiElement> extends LineMarkerProviderDescriptor {

    /**
     * 判断是否是需要标记的行
     * @param psiElement
     * @return
     */
    protected abstract boolean isMarkerTarget(@NotNull PsiElement psiElement);

    @Override
    @NotNull
    public abstract Icon getIcon();


    @Override
    public String getName() {
        return this.getClass().getName();
    }

    protected T getObject(PsiElement psiElement){
        if (!isMarkerTarget(psiElement)){
            return null;
        }
        return (T)psiElement;
    }
}
